﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using RearLivestock.Common.Domains.Common;
using RearLivestock.Common.Domains.hq;
using RearLivestock.Common.Dtos;
using RearLivestock.RBAC.Api.Application.hqApplication.Commands.Departmentss;

namespace RearLivestock.RBAC.Api.Controllers.hq
{
    /// <summary>
    /// 部门控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        private readonly IMediator imediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="imediaManager"></param>
        public DepartmentController(IMediator imediator)
        {
            this.imediator = imediator;
        }

        /// <summary>
        /// 获取部门区域
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<CascaderDto>>> GetDepartmentArea([FromQuery] SearchDepartmentAreaCommand cmd)
        {
            return await imediator.Send(cmd);
        }

        /// <summary>
        /// 获取部门
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<CascaderDto>>> GetDepartment([FromQuery] SearchDepartmentTreeCommand cmd)
        {
            return await imediator.Send(cmd);
        }

        /// <summary>
        /// 获取部门类别
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<DepartmentType>>> GetDepartmentType([FromQuery] SearchDepartmentTypeCommand cmd)
        {
            return await imediator.Send(cmd);
        }

        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddDepartments(AddDepartmentCommand cmd)
        {
            cmd.OperationTime = DateTime.Now;
            return await imediator.Send(cmd);
        }

        /// <summary>
        /// 获取部门类别
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<DepartmentDto>>> GetPageDepartment(ShowDepartmentCommand cmd)
        {
            return await imediator.Send(cmd);
        }
    }
}
